<%@ page import="java.util.*,com.db.tracker.vo.*,java.util.*,com.db.tracker.util.*,java.text.*,java.io.*"%>
<%@ page import="com.db.tracker.vo.ReleaseVO"%>
<%@ page import="com.db.tracker.vo.UnixScriptBean"%>
<%@ page session = "true" %>
<%
				
				session = request.getSession();
			//	System.out.println("user_id..main"+ session.getAttribute("USER_ID"));
			String userid = (String)session.getAttribute("USER_ID")==null?"":(String)session.getAttribute("USER_ID");
			//String ftr_user = (String)request.getParameter("ftr_user")==null?"0":request.getParameter("ftr_user");
			
			
			// for unix 
			
			ShellUtilities shellutil = new ShellUtilities(getServletContext());
			DBUtil dbutil = new DBUtil(getServletContext());
					Vector unixRelVector = new Vector();
				if(session.getAttribute("UNIX-REL-VECTOR")!= null){
					unixRelVector = (Vector)session.getAttribute("UNIX-REL-VECTOR");
				}else{
					unixRelVector = shellutil.getUnixRelease(null, 0);
					if(unixRelVector!=null){
						session.removeAttribute("UNIX-REL-VECTOR");
						session.setAttribute("UNIX-REL-VECTOR",unixRelVector);
					}
				}
              Vector searchResults = new Vector();
					searchResults = null;


             // end Unix 
             	String getreport = (String)request.getParameter("getreportbutton")==null?"":request.getParameter("getreportbutton");
                String releaseName = (String)request.getParameter("releaseName")==null?"":request.getParameter("releaseName");
                String seruser = (String)request.getParameter("seruser")==null?"0":request.getParameter("seruser");
               System.out.println( getreport +"releaseName :"+releaseName +" seruser :"+seruser);
             	if(getreport.equals("Get Report")){
				    searchResults = shellutil.getUnixSearchedReleased(releaseName,
					 seruser);
					 System.out.println("searchResults.size() -------:"+searchResults.size());
					
					}
			%>
<html>
	<head>
		<link type="text/css" rel="stylesheet" href="styles/tracker_style.css">
		<title>
			Release Reports
		</title>
		<script>

			function checkForRelease(obj){
			
			 if( obj.value == 0){
					alert("Kindly select Release Name from the list.");
					obj.focus();
					return false;
				 }

				 document.searchReleaseReport.submit();
			}

			function exportToExcelForCR(relName)
				{
					document.FilterReportDisplayForm.action = "ExportToExcelForCRNotes.jsp";	
					document.FilterReportDisplayForm.submit();
					document.FilterReportDisplayForm.action = "UnixReleaseReport.jsp";
			 	}
				
			function submitThisForReport()
				{
					document.searchReleaseReport.releaseName.value = document.FilterReportDisplayForm.hiddenrelname.value
					document.searchReleaseReport.filterreportbutton.value = "Get Filter Report";
					document.searchReleaseReport.submit();
					document.FilterReportDisplayForm.submit();
				}

			function exportToExcelForFilter()
				{
					document.FilterReportDisplayForm.action = "ExportToExcelForFilter.jsp";	
					document.FilterReportDisplayForm.submit();
					document.FilterReportDisplayForm.action = "UnixReleaseReport.jsp";
				}
			function exportToExcelForDBA()
				{
					document.ReleaseDBAReportDisplay.action = "ExportToExcelForDBA.jsp";	
					document.ReleaseDBAReportDisplay.submit();
					document.ReleaseDBAReportDisplay.action = "UnixReleaseReport.jsp";
				}	


			function trim(sString)
				  {
					sTrimmedString = "";
				    if (sString != "") {
					  var iStart = 0;
					  var iEnd = sString.length - 1;
					  // var sWhitespace = " \t\f\n\r\v";
					  var sWhitespace = "   ";
		
		
					  while (sWhitespace.indexOf(sString.charAt(iStart)) != -1) {
						 iStart++;
						 if (iStart > iEnd) 
							break;
					  }

					  // If the string not just whitespace
					  if (iStart <= iEnd) {
						 while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1)
							iEnd--;
							 sTrimmedString = sString.substring(iStart,++iEnd);
						  }
					   }
				   return sTrimmedString;
				 }

		  function checkforempty()
			{
			
				document.ReleaseExecuteForm.unixServerForRel.value =trim(document.ReleaseExecuteForm.unixServerForRel.value);
				document.ReleaseExecuteForm.unixServerUserid.value =trim(document.ReleaseExecuteForm.unixServerUserid.value);
				document.ReleaseExecuteForm.unixServerPwd.value =trim(document.ReleaseExecuteForm.unixServerPwd.value);
			
			
				if(submitForms(document.ReleaseExecuteForm.unixServerForRel, document.ReleaseExecuteForm.unixServerUserid, document.ReleaseExecuteForm.unixServerPwd))
				{
					document.ReleaseExecuteForm.Act.value = "Execute Shell for Release";
					document.ReleaseExecuteForm.submit();
				}
				
			}


			function checkforempty2()
			{
			
				document.ReleaseExecuteForm.unixServerForRel.value =trim(document.ReleaseExecuteForm.unixServerForRel.value);
				document.ReleaseExecuteForm.unixServerUserid.value =trim(document.ReleaseExecuteForm.unixServerUserid.value);
				document.ReleaseExecuteForm.unixServerPwd.value =trim(document.ReleaseExecuteForm.unixServerPwd.value);
			
			
				if(submitForms(document.ReleaseExecuteForm.unixServerForRel, document.ReleaseExecuteForm.unixServerUserid, document.ReleaseExecuteForm.unixServerPwd))
				{
					document.ReleaseExecuteForm.Act.value = "Get Log for Release";
					document.ReleaseExecuteForm.submit();
				}
				
			}


			function submitForms(obj1, obj2, obj3){
	
			    if (obj1.value.length == 0 ){
					alert("Please enter unix server name.");
					obj1.focus();
					return false;
				 }

				 if( obj2.value.length == 0){
					alert("Please enter unix server userid.");
					obj2.focus();
					return false;
				 }

				 if( obj3.value.length == 0){
					alert("Please enter unix server password.");
					obj3.focus();
					return false;
				}
			
				return true;
				//  document.updateRelease.submit();
				//  document.searchReleaseForm.submit();
	
				//document.displayForm.submit();
		  	
		  				//  document.MainForm.submit();
						//alert("HIIIIIII");
			}
		
		function overviewCRDetails(ReleaseObjKey) {
			dwin=window.open("OverviewCRDetail.jsp?relobjkey="+ReleaseObjKey,"detailWin","width=900,height=600,scrollbars=yes,resizable=yes");
			dwin.focus();
		
		}
		</script>
	</head>

	<body>
		
		<form name="ReleaseReport" method="post">

      	<table width=100%>
				<tr>
					<td width=100%>
						<jsp:include page="HeaderNav_ReleaseObject.jsp" />
					</td>
				</tr>
			</table>
			</form>




		<a href="mainpage.jsp">Back to Main Page.</a>
		
		<form name="searchReleaseReport" action="UnixReleaseReport.jsp" method="post">
		
			<table cellpadding="0" cellspacing="1" width="100%" style="BORDER:#000000 1px solid">
				<tr bgcolor=#EFEFEF>
					<td class=bodyblue>
						<b>
							Release Name
						</b>
					</td>

					<td class=bodyblue>
						<select name=releaseName>

							 <option value='0' <% out.println("selected");%>>
								Select Release
							</option>
						<% 
								UnixReleaseBean urBean = new UnixReleaseBean();
								for(int i=0;i<unixRelVector.size();i++)
								{
									urBean =(UnixReleaseBean)unixRelVector.elementAt(i); 
							%>
							<option value= '<%=urBean.getUnixReleaseName()%>' 
										<%=releaseName.equals(urBean.getUnixReleaseName())?"selected":"" %>	
											
											> 
											<%= urBean.getUnixReleaseName()%> </option>
							
							<%	
							}
							
							%>
						</select>
					</td>

            
                     	<td class=bodyblue>
								<b>
									User Updated
								</b>
							</td>
							
							<td class = bodyblue width="15%" colspan="1">
								<select name=seruser onChange="JavaScript:submitThisForReport()" >
								<option value='ALL' >- ALL -</option>
								<% 
									Vector userList = shellutil.getUnixUsersForRelease();
									
									if(userList !=null && userList.size()>0){
									for(int i=0;i<userList.size();i++)
									{	
										ReleaseVO uservo =(ReleaseVO)userList.elementAt(i); 
								%>
	
										<option value= '<%=uservo.getUserUpdated()%>' 
										<%=seruser.equals(uservo.getUserUpdated())?"selected":"" %>	
											
											> 
											<%= uservo.getUserUpdated()%> </option>
					
								<%	} 
								}
								%>
								</select>
						</td>
					<td>
						<input type=submit class=whitebutton name="getreportbutton" value="Get Report" onclick="return checkForRelease(releaseName)">
					</td>
				</tr>
			</table>
			

			<%if (searchResults != null && searchResults.size() != 0) {
		     %>
			
			
			<table cellpadding="0" cellspacing="1" width="100%" style="BORDER:#000000 1px solid" >
			
				<tr bgcolor=##000077 >
					<td class=smallfonthead ><b> Location </b></td>
					<td class=smallfonthead ><b> Shell Name</b></td>
					<td class=smallfonthead ><b> SVN Location </b></td>
					<td class=smallfonthead ><b> Delpoyment Location  </b></td>
					<td class=smallfonthead ><b> Contact Person</b></td>
			  </tr>
				<tr>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
			
			
					<%
					 if(searchResults != null && searchResults.size()>0) {
					 for (int i=0;i<searchResults.size();i++){	
						 	UnixScriptBean dispVo = (UnixScriptBean) searchResults
										.elementAt(i);
								 String baccolor="";
								  if(i%2==0){
								baccolor="#C2D6EB";
								}
							else{ 
								baccolor="#EFEFEF";
								}

					%>
				
						<tr bgcolor=<%=baccolor%>>
							     <input type=hidden name=releaseList value='<%=dispVo.getUnixReleaseName()%>' >
								<td class=bodyblue colspan=1 width="10%" align='center'>
									 <%= dispVo.getCountryLocation() %>
								</td>
								<td  colspan=1 width="10%" align='center'>
								
								 <%= dispVo.getShellName() %>
									
								</td>
			
								<td  colspan=1 width="27%" align='center'>
									
									<%= dispVo.getRepoLocation() %>
								</td>
								
								<td  colspan=1 width="27%" align='center'>
									
									<%= dispVo.getDeploymentLocation() %>
								</td>
								
								<td  colspan=1 width="15%" align='center'>
									<%=dispVo.getUserUpdated()%>
								</td>
					</tr>	
			<% }
			}%>				

			</table>	
		<%}%>
		
		<%
		if(getreport.equals("Get Report"))
		{
		if(searchResults.size() == 0) {
		%>
		<table cellpadding="0" cellspacing="1" width="100%" style="BORDER:#000000 1px solid">
			<tr bgcolor="#000077">

				<td class=smallfonthead>
					<b>
						No Results for this Criteria
					</b>
				</td>

			</tr>
		</table>
		  
		<% }
		}%>
			
		</form>
		
	</body>
</html>

